package com.zhangj.controller;

import com.zhangj.pojo.User;
import com.zhangj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName UserController
 * @Description
 * @Author zhangjie
 * @Date 2022/1/11 18:28
 * @Version 1.0
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userService.findUsers();
    }

    @RequestMapping("/findOne")
    public User findUserById(Long id){
        return userService.findUserById(id);
    }

    @RequestMapping("/add")
    public void addUser(@RequestBody User user){
        userService.saveUser(user);
    }

    @RequestMapping("/update")
    public void update(@RequestBody User user){
        userService.updateUser(user);
    }

    @RequestMapping("delete")
    public void delete(Long id){
        userService.deleteUserById(id);
    }
}
